package main

import (
	"context"
	clientv3 "go.etcd.io/etcd/client/v3"
	"log"
	"time"
)

func main() {
	// 创建 etcd 客户端
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"127.0.0.1:12379"},
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		log.Fatalf("Failed to connect to etcd: %v", err)
	}
	defer cli.Close()

	// YAML 配置内容
	yamlContent := `db.mysql:
  dsn: "root:root@tcp(localhost:13316)/webook"

redis:
  addr: "localhost:6379"
  password: ""
  db: 0
`

	// 写入到 etcd
	_, err = cli.Put(context.Background(), "/webook", yamlContent)
	if err != nil {
		log.Fatalf("Failed to write to etcd: %v", err)
	}

	log.Println("Successfully wrote YAML content to etcd.")
}
